/*
 * Project: Generic Project Controls
 * Package: net.made2ordersoftware.control
 * File:    AbstractControl
 * Created: May 22, 2010
 */

/*
 *  Copyright 2010 Made 2 Order Software, LLC
 *
 *  All rights reserved. No part of this software may be reproduced, stored in a retrieval system, or
 *  transmitted in any form or by any means, without the prior written permission of Made 2 Order Software.
 *
 *  You may not distribute the URL or redistribute the files to third parties. You may transfer the files
 *  onto a single storage device so long as you can prove ownership of the software. You may not reverse
 *  engineer, decompile, or disassemble the software or media files. You may not modify or translate the
 *  software or media, or distribute copies of the software or media without the written consent of Made
 *  2 Order Software
 */
package com.made2ordersoftware.control;

import java.io.Serializable;
import java.util.Map;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.context.Flash;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * An abstract controlling class to help managed all JSF controlling managed beans.
 *
 * @author David Canning
 * @version 1.0
 */
@RequestScoped
public abstract class AbstractControl implements Serializable {

   protected final static Logger LOG = LoggerFactory.getLogger(AbstractControl.class);
   @ManagedProperty(value = "#{facesContext}")
   private FacesContext facesContext;
   @ManagedProperty(value = "#{requestMap}")
   private Map<String, Object> requestMap;
   @ManagedProperty(value = "#{sessionMap}")
   private Map<String, Object> sessionMap;

   /**
    * Returns the JSF
    * <code>Flash</code> object for this session.
    *
    * @return The current <code>Flash</code> object.
    */
   public Flash getFlash() {
      return getFacesContext().getExternalContext().getFlash();
   }

   /**
    * Returns the current
    * <code>RequestMap</code> map for this request.
    *
    * @return The current session's RequestMap object.
    */
   public Map<String, Object> getRequestMap() {
      return getFacesContext().getExternalContext().getRequestMap();
   }

   /**
    * Sets the current
    * <code>RequestMap</code> map for this request.
    *
    * @param requestMap The current session's requestMap object.
    */
   public void setRequestMap(Map<String, Object> requestMap) {
      this.requestMap = requestMap;
   }

   /**
    * Returns the current
    * <code>SessionMap</code> map for this session.
    *
    * @return The current session's sessionMap.
    */
   public Map<String, Object> getSessionMap() {
      return getFacesContext().getExternalContext().getSessionMap();
   }

   /**
    * Sets the current
    * <code>SessionMap</code> map for this session.
    *
    * @param sessionMap The current session's sessionMap.
    */
   public void setSessionMap(Map<String, Object> sessionMap) {
      this.sessionMap = sessionMap;
   }

   /**
    * Returns the current
    * <code>FacesContext</code> map for this session.
    *
    * @return The current sessions FacesContext object.
    */
   public FacesContext getFacesContext() {
      return FacesContext.getCurrentInstance();
   }

   /**
    * Sets the current
    * <code>FacesContext</code> map for this session.
    *
    * @param context The FacesContext object representing the current session.
    */
   public void setFacesContext(FacesContext context) {
      this.facesContext = context;
   }
}
